#include "settingswidget.h"
#include <QPushButton>
#include <QGridLayout>
#include <QFile>
#include <QSpacerItem>
#include "configargs.h"
#include <QLabel>
#include <QDebug>
SettingsWidget::SettingsWidget(QWidget *parent) : QWidget(parent)
{
    QPushButton *pNetWorkingBtn = new QPushButton();
    pNetWorkingBtn->setFocusPolicy(Qt::NoFocus);
    pNetWorkingBtn->setObjectName("netWorkingBtn");

    QLabel *netLabel = new QLabel(tr("  网络设置"));
    QLabel *touLabel = new QLabel(tr("     校准"));
    QLabel *wifiLabel = new QLabel(tr("  WIFI设置"));
    QLabel *ceshiLabel = new QLabel(tr("  硬件检测"));
//    QLabel *cputempLabel = new QLabel(tr("  温度曲线"));
    QLabel *performanceLabel = new QLabel(tr("性能测试"));
    QLabel *versionLabel = new QLabel(tr("版本信息"));
    QLabel *RNDISLabel = new QLabel(tr("RNDIS网络"));

    QPushButton *pTouchCalBtn = new QPushButton();
    pTouchCalBtn->setFocusPolicy(Qt::NoFocus);
    pTouchCalBtn->setObjectName("touchCalBtn");

    QPushButton *pTouchWifiBtn = new QPushButton();
    pTouchWifiBtn->setFocusPolicy(Qt::NoFocus);
    pTouchWifiBtn->setObjectName("wifiBtn");

    QPushButton *pTouchCeshiBtn = new QPushButton();
    pTouchCeshiBtn->setFocusPolicy(Qt::NoFocus);
    pTouchCeshiBtn->setObjectName("ceshiBtn");

    QPushButton *pTouchCputempBtn = new QPushButton();
    pTouchCputempBtn->setFocusPolicy(Qt::NoFocus);
    pTouchCputempBtn->setObjectName("cputempBtn");

    QPushButton *pPerformanceBtn = new QPushButton(this); 
    pPerformanceBtn->setFocusPolicy(Qt::NoFocus);
    pPerformanceBtn->setObjectName("performanceBtn");
	performanceLabel->setAlignment(Qt::AlignCenter);

    QPushButton *pVersionInfoBtn = new QPushButton(this);
    pVersionInfoBtn->setFocusPolicy(Qt::NoFocus);
    pVersionInfoBtn->setObjectName("versionInfoBtn");
    versionLabel->setAlignment(Qt::AlignCenter);

    QPushButton *pRNDISBtn = new QPushButton(this);
    pRNDISBtn->setFocusPolicy(Qt::NoFocus);
    pRNDISBtn->setObjectName("RNDISBtn");
    RNDISLabel->setAlignment(Qt::AlignCenter);


    QGridLayout *pMainLayout = new QGridLayout();
    QSpacerItem *pSpacerItem = new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Expanding);

    if(g_lcdsize == LCDSIZE_1280x800)
        {
            netLabel->setText(tr("网络设置"));
            touLabel->setText(tr("触摸屏"));
            wifiLabel->setText(tr("WIFI设置"));
            ceshiLabel->setText(tr("硬件检测"));
            versionLabel->setText(tr("版本信息"));

            netLabel->setAlignment(Qt::AlignCenter);
            touLabel->setAlignment(Qt::AlignCenter);
            wifiLabel->setAlignment(Qt::AlignCenter);
            ceshiLabel->setAlignment(Qt::AlignCenter);
            versionLabel->setAlignment(Qt::AlignCenter);

            netLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");
            touLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");
            wifiLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");
            ceshiLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");
            performanceLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");
            versionLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");


            pMainLayout->setMargin(20);
            pMainLayout->setSpacing(20);

            pMainLayout->addWidget(pNetWorkingBtn, 0, 0, 1, 1);
            pMainLayout->addWidget(pTouchWifiBtn, 0, 1, 1, 1);
            pMainLayout->addWidget(pTouchCalBtn, 0, 2, 1, 1);
            pMainLayout->addWidget(pTouchCeshiBtn, 0, 3, 1, 1);
            pMainLayout->addWidget(pPerformanceBtn, 0, 4, 1, 1);

            pMainLayout->addWidget(pVersionInfoBtn, 0, 5, 1, 1);

            pMainLayout->addWidget(netLabel, 1, 0, 1, 1);
            pMainLayout->addWidget(wifiLabel, 1, 1, 1, 1);
            pMainLayout->addWidget(touLabel, 1, 2, 1, 1);
            pMainLayout->addWidget(ceshiLabel, 1, 3, 1, 1);
            pMainLayout->addWidget(performanceLabel, 1, 4, 1, 1);
            pMainLayout->addWidget(versionLabel, 1, 5, 1, 1);

            pMainLayout->addWidget(pRNDISBtn, 2, 0, 1, 1);
            pMainLayout->addWidget(RNDISLabel, 3, 0, 1, 1);

            pMainLayout->addItem(pSpacerItem, 4, 0, 1, 6);
            pMainLayout->addItem(pSpacerItem, 5, 0, 1, 6);
            pMainLayout->addItem(pSpacerItem, 6, 0, 1, 6);

        }else if(g_lcdsize == LCDSIZE_1024x768){
		netLabel->setText(tr("网络设置"));
		touLabel->setText(tr("触摸屏"));
		wifiLabel->setText(tr("WIFI设置"));
        ceshiLabel->setText(tr("硬件检测"));
        versionLabel->setText(tr("版本信息"));

		netLabel->setAlignment(Qt::AlignCenter);
		touLabel->setAlignment(Qt::AlignCenter);
		wifiLabel->setAlignment(Qt::AlignCenter);
		ceshiLabel->setAlignment(Qt::AlignCenter);
        versionLabel->setAlignment(Qt::AlignCenter);

		netLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");
		touLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");		  
		wifiLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");    
		ceshiLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");   
		performanceLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");
        versionLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");


		pMainLayout->setMargin(20);
		pMainLayout->setSpacing(20);

		pMainLayout->addWidget(pNetWorkingBtn, 	0, 0, 1, 1);
		pMainLayout->addWidget(pTouchWifiBtn,	0, 1, 1, 1);
		pMainLayout->addWidget(pTouchCalBtn, 	0, 2, 1, 1);
		pMainLayout->addWidget(pTouchCeshiBtn, 	0, 3, 1, 1);
		pMainLayout->addWidget(pPerformanceBtn, 	0, 4, 1, 1);


		pMainLayout->addWidget(netLabel, 		1, 0, 1, 1);
		pMainLayout->addWidget(wifiLabel, 		1, 1, 1, 1);
        pMainLayout->addWidget(touLabel, 		1, 2, 1, 1);
		pMainLayout->addWidget(ceshiLabel, 		1, 3, 1, 1);
		pMainLayout->addWidget(performanceLabel, 1, 4, 1, 1);

        pMainLayout->addWidget(pVersionInfoBtn, 2, 0, 1, 1);
        pMainLayout->addWidget(versionLabel, 3, 0, 1, 1);

        pMainLayout->addWidget(pRNDISBtn, 2, 1, 1, 1);
        pMainLayout->addWidget(RNDISLabel, 3, 1, 1, 1);


        pMainLayout->addItem(pSpacerItem, 4, 0, 14, 7);
    }
    else if(g_lcdsize == LCDSIZE_800x600){
		netLabel->setText(tr("网络设置"));
		touLabel->setText(tr("触摸屏"));
		wifiLabel->setText(tr("WIFI设置"));
		ceshiLabel->setText(tr("硬件检测"));
        versionLabel->setText(tr("版本信息"));

		netLabel->setAlignment(Qt::AlignCenter);
		touLabel->setAlignment(Qt::AlignCenter);
		wifiLabel->setAlignment(Qt::AlignCenter);
		ceshiLabel->setAlignment(Qt::AlignCenter);
        versionLabel->setAlignment(Qt::AlignCenter);

		netLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");
		touLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");		   
		wifiLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");	
		ceshiLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");	
		performanceLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");
        versionLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");

		pMainLayout->setMargin(20);
		pMainLayout->setSpacing(20);

		pMainLayout->addWidget(pNetWorkingBtn, 0, 0, 1, 1);
		pMainLayout->addWidget(pTouchWifiBtn, 0, 1, 1, 1);
		pMainLayout->addWidget(pTouchCalBtn, 0, 2, 1, 1);
		pMainLayout->addWidget(pTouchCeshiBtn, 0, 3, 1, 1);
		pMainLayout->addWidget(pPerformanceBtn, 0, 4, 1, 1);

		pMainLayout->addWidget(netLabel, 1, 0, 1, 1);
		pMainLayout->addWidget(wifiLabel, 1, 1, 1, 1);
		pMainLayout->addWidget(touLabel, 1, 2, 1, 1);
		pMainLayout->addWidget(ceshiLabel, 1, 3, 1, 1);
		pMainLayout->addWidget(performanceLabel, 1, 4, 1, 1);


        pMainLayout->addWidget(pVersionInfoBtn, 2, 0, 1, 1);
        pMainLayout->addWidget(versionLabel, 3, 0, 1, 1);

        pMainLayout->addWidget(pRNDISBtn, 2, 1, 1, 1);
        pMainLayout->addWidget(RNDISLabel, 3, 1, 1, 1);

        pMainLayout->addItem(pSpacerItem, 4, 0, 14, 6);

    }
	else if(g_lcdsize == LCDSIZE_800x480)
	{
		netLabel->setText(tr("网络设置"));
		touLabel->setText(tr("触摸屏"));
		wifiLabel->setText(tr("WIFI设置"));
		ceshiLabel->setText(tr("硬件检测"));
        versionLabel->setText(tr("版本信息"));

		netLabel->setAlignment(Qt::AlignCenter);
		touLabel->setAlignment(Qt::AlignCenter);
		wifiLabel->setAlignment(Qt::AlignCenter);
		ceshiLabel->setAlignment(Qt::AlignCenter);
        versionLabel->setAlignment(Qt::AlignCenter);

		netLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");
		touLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");		   
		wifiLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");	
		ceshiLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");	
		performanceLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");
        versionLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");


		pMainLayout->setMargin(20);
		pMainLayout->setSpacing(20);

		pMainLayout->addWidget(pNetWorkingBtn, 0, 0, 1, 1);
		pMainLayout->addWidget(pTouchWifiBtn, 0, 1, 1, 1);
		pMainLayout->addWidget(pTouchCalBtn, 0, 2, 1, 1);
		pMainLayout->addWidget(pTouchCeshiBtn, 0, 3, 1, 1);
		pMainLayout->addWidget(pPerformanceBtn, 0, 4, 1, 1);

        pMainLayout->addWidget(pVersionInfoBtn, 2, 0, 1, 1);

		pMainLayout->addWidget(netLabel, 1, 0, 1, 1);
		pMainLayout->addWidget(wifiLabel, 1, 1, 1, 1);
		pMainLayout->addWidget(touLabel, 1, 2, 1, 1);
		pMainLayout->addWidget(ceshiLabel, 1, 3, 1, 1);
		pMainLayout->addWidget(performanceLabel, 1, 4, 1, 1);

        pMainLayout->addItem(pSpacerItem, 2, 3, 1, 1);

        pMainLayout->addWidget(versionLabel, 3, 0, 1, 1);

        pMainLayout->addWidget(pRNDISBtn, 2, 1, 1, 1);
        pMainLayout->addWidget(RNDISLabel, 3, 1, 1, 1);

        pMainLayout->addItem(pSpacerItem, 5, 3, 1, 1);

    }else if(g_lcdsize == LCDSIZE_480x272)
	{
		netLabel->setText(tr("有线网"));
		touLabel->setText(tr("触摸屏"));
		wifiLabel->setText(tr("WIFI"));
		ceshiLabel->setText(tr("硬件检测"));
		performanceLabel->setText(tr("性能测试"));
        versionLabel->setText(tr("版本信息"));

		netLabel->setAlignment(Qt::AlignCenter);
		touLabel->setAlignment(Qt::AlignCenter);
		wifiLabel->setAlignment(Qt::AlignCenter);
		ceshiLabel->setAlignment(Qt::AlignCenter);
		performanceLabel->setAlignment(Qt::AlignCenter);
        versionLabel->setAlignment(Qt::AlignCenter);

		netLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");
		touLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);"); 	   
		wifiLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");	
		ceshiLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");
		performanceLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");
        versionLabel->setStyleSheet("color: rgba(29, 122, 199, 100%);");


		pMainLayout->setMargin(20);

		if(g_lcdsize == LCDSIZE_480x272)
		{
			pMainLayout->setSpacing(20);
		}else{
			pMainLayout->setSpacing(10);
		}
		pMainLayout->addWidget(pNetWorkingBtn,	0, 0, 1, 1);
		pMainLayout->addWidget(pTouchWifiBtn,	0, 1, 1, 1);
		pMainLayout->addWidget(pTouchCalBtn, 	0, 2, 1, 1);  
		pMainLayout->addWidget(pTouchCeshiBtn,	0, 3, 1, 1);
		pMainLayout->addWidget(pPerformanceBtn,	0, 4, 1, 1);

		pMainLayout->addWidget(netLabel, 		1, 0, 1, 1);
		pMainLayout->addWidget(wifiLabel,		1, 1, 1, 1);
		pMainLayout->addWidget(touLabel, 		1, 2, 1, 1);			   
		pMainLayout->addWidget(ceshiLabel,		1, 3, 1, 1);
		pMainLayout->addWidget(performanceLabel, 1, 4, 1, 1);

        pMainLayout->addWidget(pVersionInfoBtn, 2, 0, 1, 1);

		pMainLayout->addItem(pSpacerItem, 2, 3, 1, 1);

        pMainLayout->addWidget(versionLabel, 3, 0, 1, 1);

        pMainLayout->addWidget(pRNDISBtn, 2, 1, 1, 1);
        pMainLayout->addWidget(RNDISLabel, 3, 1, 1, 1);


    }


	
    this->setLayout(pMainLayout);
    connect(pNetWorkingBtn, SIGNAL(clicked(bool)), this, SIGNAL(netWorkingBtnClicked()));
    connect(pTouchCalBtn, SIGNAL(clicked(bool)), this, SIGNAL(touchCalBtnClicked()));
    connect(pTouchWifiBtn, SIGNAL(clicked(bool)), this, SIGNAL(wifiWorkingBtnClicked()));
    connect(pTouchCeshiBtn, SIGNAL(clicked(bool)), this, SIGNAL(ceshiWorkingBtnClicked()));
    connect(pTouchCputempBtn, SIGNAL(clicked(bool)), this, SIGNAL(cpuTempBtnClicked()));
	connect(pPerformanceBtn, SIGNAL(clicked(bool)), this, SIGNAL(performanceBtnClicked()));
    connect(pVersionInfoBtn, SIGNAL(clicked(bool)), this, SIGNAL(versionInfoBtnClicked()));
    connect(pRNDISBtn, SIGNAL(clicked(bool)), this, SIGNAL(RNDISBtnClicked()));

    loadQss();
}

void SettingsWidget::loadQss()
{
    QFile iconQss(":/qss/linuxdesktop/stylesheet/settingsicon.qss");
    iconQss.open(QFile::ReadOnly);
    QString iconQssStr = iconQss.readAll();

    QFile sizeQss;
    if(g_lcdsize == LCDSIZE_1024x768){
    	sizeQss.setFileName(":/qss/linuxdesktop/stylesheet/settingssize_1024x768.qss");
    }else if(g_lcdsize == LCDSIZE_800x600){
		sizeQss.setFileName(":/qss/linuxdesktop/stylesheet/settingssize_800x600.qss");
    }else if(g_lcdsize == LCDSIZE_800x480){
      sizeQss.setFileName(":/qss/linuxdesktop/stylesheet/settingssize.qss");
    }else if(g_lcdsize == LCDSIZE_480x272){
      sizeQss.setFileName(":/qss/linuxdesktop/stylesheet/settingssize_480x272.qss"); 
    }else if(g_lcdsize == LCDSIZE_1280x800){
        sizeQss.setFileName(":/qss/linuxdesktop/stylesheet/settingssize_1280x800.qss");
      }

    sizeQss.open(QFile::ReadOnly);
    QString sizeQssStr = sizeQss.readAll();
	
    this->setStyleSheet(sizeQssStr + iconQssStr);
}
